package com.avic.rong.course.activity.otherActivity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.avic.rong.BaseActivity;
import com.avic.rong.R;
import com.avic.rong.course.adapter.AuthorIntroductionRvAdapter;
import com.avic.rong.course.bean.PeiXunJiangShiBean;
import com.avic.rong.course.showapi.PeiXunAuthorSummaryApi;
import com.avic.rong.utils.ConstantsUtils;
import com.avic.rong.utils.ToastTools;
import com.example.minato.minastore.BaseResultEntity;
import com.example.minato.minastore.http.HttpManager;
import com.example.minato.minastore.listener.HttpOnNextListener;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PeiXunIntroductionActivity extends BaseActivity {

    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.ll_root)
    LinearLayout llRoot;
    @BindView(R.id.jieshao_rv)
    RecyclerView jieshaoRv;

    private AuthorIntroductionRvAdapter rvAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pei_xun_introduction);
        ButterKnife.bind(this);
        ivRight.setImageResource(R.mipmap.slh);
        tvTitle.setText("讲师介绍");
        ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ivRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopup(PeiXunIntroductionActivity.this,llRoot);
            }
        });
        String courseId = getIntent().getStringExtra(PeiXunClassMuLuActivity.COURSESID);
        initAuthorData(courseId);
    }

    private void initAuthorData(String courseId) {
        PeiXunAuthorSummaryApi classMuLuApi = new PeiXunAuthorSummaryApi(this, simpleOnNextListener, courseId);
        classMuLuApi.setCache(false);
        HttpManager.getInstance().doHttpDeal(classMuLuApi);
    }
    //获取讲师介绍列表数据监听
    HttpOnNextListener simpleOnNextListener = new HttpOnNextListener<BaseResultEntity>() {
        @Override
        public void onNext(BaseResultEntity subjects) {
            if (!subjects.getCode().equals(ConstantsUtils.STATUS_SUCCESS_0000)) {
                ToastTools.showToast(PeiXunIntroductionActivity.this, subjects.getMsg());
                Log.e("cjx", subjects.getMsg());
                return;
            }
            ArrayList<PeiXunJiangShiBean> beans = (ArrayList<PeiXunJiangShiBean>) subjects.getResult();
            jieshaoRv.setLayoutManager(new LinearLayoutManager(PeiXunIntroductionActivity.this));
            rvAdapter = new AuthorIntroductionRvAdapter(PeiXunIntroductionActivity.this,beans);
            jieshaoRv.setAdapter(rvAdapter);
        }

        @Override
        public void onCacheNext(String cache) {
        }

        @Override
        public void onError(final Throwable e) {
            Log.e("cjx", "培训课时目录列表数据：" + e.getMessage());
        }
    };


    @Override
    protected int getContentViewId() {
        return 0;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void addListener() {

    }
}
